﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Web.UI.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.TreeViews;
using TreeNode = Ue.Qcdz.Domain.TreeViews.TreeNode;
using TreeView = Ue.Qcdz.Domain.TreeViews.TreeView;

namespace Ue.Qcdz.UI.Controls.Medias
{
    public class MediaView : SkinnedGridView
    {
        private string skinFileName = "~/Themes/zh-cn/Skins/Medias/MediasView.ascx";
        private TreeView treeView;
        private ITreeViewRepository repository;
        public string TreeNoId { get; set; }
        public string TagId { get; set; }
        public MediaView()
        {
            repository =
                       Ue.Infrastructure.RepositoryFramework.RepositoryFactory.GetRepository
                           <ITreeViewRepository, TreeView>();
        }

        #region MyRegion
        protected override void GridViewDataBind(object sender, EventArgs args)
        {
            treeView = repository.FindBy(TreeNoId);

            IEnumerable<TreeNode> treeNodes = treeView.FindNodeBy(TagId).ChildNodes;
            
            Repeater repeater = sender as Repeater;
            repeater.DataSource = treeNodes;
            repeater.DataBind();
        }

        protected override string GetSkinFileName()
        {
            return skinFileName;
        } 
        #endregion
    }
}
